#include "stdafx.h"
#include "./playerai.h"

#define LUA_FUNC_NAME "DoAI"

PlayerAI::PlayerAI(int id,
				   string strName, 
				   Point startPos, 
				   float startAngle, 
				   Point hpPos,
				   float z,
				   Color color)
: PlayerMsg(id, strName, startPos, startAngle, hpPos, z, color)
{
	m_luathread = LuaEx::GetInstance().NewThread();

	m_playermsgobj = LuaEx::GetInstance().GetLuaObject(reinterpret_cast<PlayerMsg*>(this));
	m_playerobj = LuaEx::GetInstance().GetLuaObject(reinterpret_cast<Player*>(this));

	string strFunName = strName + "." + LUA_FUNC_NAME;
	m_funcobj = LuaEx::GetInstance().LoadFunc(strFunName.c_str());
}

PlayerAI::~PlayerAI()
{
}

void PlayerAI::DoAI(TankMsg* pMsg)
{
	PlayerMsg::SetMsg(pMsg);

	//Call Lua
	bool succeed = LuaEx::GetInstance().CallThreadFunc(m_luathread, m_funcobj, m_playermsgobj);

	PlayerMsg::ClearMsg();
}

luaobj& PlayerAI::GetPlayerObj()
{
	return m_playerobj;
}